package org.game.plugin.event;

import java.util.Map;
import java.util.Stack;

import org.constant.EventConditionKey;
import org.game.db.bean.Player;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

/**
 * 事件
 * 
 * @author win7
 *
 */
public class GameEvent {
	private Player player;
	/**
	 * 事件类型
	 * 不同类型的事件通常由该类型对应的GameEventListener接口来处理
	 */
	private final int eventType;
	// 事件源(事件参数)
	private ImmutableMap<String, Object> in;
	// 事件输出
	Map<String,Object> out;
	// 触发条件栈
	private Stack<GameEventStack> eventStack;
	
	private Map<String, Object> firstMap = Maps.newHashMap();
	
	public GameEvent(Player player,int eventType) {
		this.player = player;
		this.eventType = eventType;
		this.in = ImmutableMap.of();
		this.eventStack = new Stack<>();
	}

	public GameEvent(Player player,int eventType, Map<String, Object> in) {
		this.player = player;
		this.eventType = eventType;
		this.in = ImmutableMap.copyOf(in);
		this.eventStack = new Stack<>();
	}

	public int getEventType() {
		return eventType;
	}

	public ImmutableMap<String, Object> getIn() {
		return in;
	}

	public Map<String, Object> getOut() {
		return out;
	}

	public Map<String, Object> getFirstMap() {
		return firstMap;
	}

	public Player getPlayer() {
		return player;
	}

	public void push(GameEventStack eventStack){
		this.eventStack.push(eventStack);
	}
	
	public GameEventStack peek(){
		if (eventStack.empty()) {
			return null;
		}
		return eventStack.peek();
	}

	/**
	 * 获取条件类型
	 */
	public int getConditionType(){
		Integer conditionType = (Integer) in.get(EventConditionKey.CONDITION_TYPE);
		if (conditionType == null){
			return 0;
		}else{
			return conditionType;
		}
	}
}